import 'package:flutter/material.dart';
import '../home1_3.dart';
import 'notification_page.dart';
import 'profile_edit_page.dart';

class ProfilePage extends StatelessWidget {
  const ProfilePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFF1DC4A0),
      body: SafeArea(
        child: Column(
          children: [
            // 顶部个人信息区域
            Padding(
              padding: const EdgeInsets.all(20),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      GestureDetector(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => const ProfileEditPage(),
                            ),
                          );
                        },
                        child: Image.asset(
                          'assets/icons/edit.png',
                          width: 24,
                          height: 24,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 10),
                  Container(
                    width: 80,
                    height: 80,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(color: Colors.white, width: 2),
                      color: Colors.lightBlue.shade200,
                    ),
                    child: ClipOval(
                      child: Image.asset(
                        'assets/icons/patient_home0.png',
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                  const SizedBox(height: 10),
                  const Text(
                    '用户a',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SizedBox(height: 5),
                  const Text(
                    'jysthlsdtdz@qq.com',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 14,
                    ),
                  ),
                ],
              ),
            ),
            // 白色区域
            Expanded(
              child: Container(
                decoration: const BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(30),
                    topRight: Radius.circular(30),
                  ),
                ),
                child: SingleChildScrollView(
                  child: Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 20),
                    child: Column(
                      children: [
                        _buildMenuOption(
                          context,
                          icon: 'assets/icons/pay.png',
                          title: '支付',
                          onTap: () {},
                        ),
                        _buildMenuOption(
                          context,
                          icon: 'assets/icons/friends.png',
                          title: '好友',
                          onTap: () {},
                        ),
                        _buildMenuOption(
                          context,
                          icon: 'assets/icons/call.png',
                          title: '联系我们',
                          onTap: () {},
                        ),
                        _buildMenuOption(
                          context,
                          icon: 'assets/icons/settings.png',
                          title: '设置',
                          onTap: () {},
                        ),
                        const SizedBox(height: 40),
                        GestureDetector(
                          onTap: () {
                            // 处理退出登录
                          },
                          child: Container(
                            padding: const EdgeInsets.symmetric(vertical: 15),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(color: Colors.grey.shade200),
                              ),
                            ),
                            child: Row(
                              children: [
                                Container(
                                  padding: const EdgeInsets.all(8),
                                  decoration: BoxDecoration(
                                    //color: Colors.grey.shade100,
                                    borderRadius: BorderRadius.circular(10),
                                  ),
                                  child: Image.asset(
                                    'assets/icons/logout.png',
                                    width: 100,
                                    height: 100,
                                    color: Colors.blue,
                                  ),
                                ),
                                const SizedBox(width: 15),
                                // const Text(
                                //   '退出',
                                //   style: TextStyle(
                                //     fontSize: 16,
                                //     fontWeight: FontWeight.w500,
                                //     color: Colors.blue,
                                //   ),
                                //),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
      bottomNavigationBar: Container(
        padding: const EdgeInsets.symmetric(vertical: 12),
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 10,
              offset: const Offset(0, -2),
            ),
          ],
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _buildNavItem(
              iconPath: 'assets/icons/home.png',
              selectedIconPath: 'assets/icons/home.png',
              label: '首页',
              isSelected: false,
              onTap: () {
                Navigator.pushReplacementNamed(context, '/home1_3');
              },
            ),
            _buildNavItem(
              iconPath: 'assets/icons/calendar.png',
              selectedIconPath: 'assets/icons/calendar.png',
              label: '服药日程',
              isSelected: false,
              onTap: () => Navigator.pushReplacementNamed(
                  context, '/medication_schedule'),
            ),
            _buildNavItem(
              iconPath: 'assets/icons/notification.png',
              selectedIconPath: 'assets/icons/notification.png',
              label: '消息',
              isSelected: false,
              onTap: () {
                Navigator.pushReplacementNamed(context, '/notification');
              },
            ),
            _buildNavItem(
              iconPath: 'assets/icons/profile.png',
              selectedIconPath: 'assets/icons/profile.png',
              label: '我的',
              isSelected: true,
              onTap: () {},
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildNavItem({
    required String iconPath,
    required String selectedIconPath,
    required String label,
    required bool isSelected,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Stack(
            alignment: Alignment.bottomCenter,
            children: [
              // 图标
              Image.asset(
                iconPath,
                width: 24,
                height: 24,
                color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
              ),
              // 选中指示器
              if (isSelected)
                Positioned(
                  bottom: -8,
                  child: Image.asset(
                    'assets/icons/chosen.png',
                    width: 16,
                    height: 3,
                  ),
                ),
            ],
          ),
          const SizedBox(height: 8),
          Text(
            label,
            style: TextStyle(
              color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
              fontSize: 12,
              fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildMenuOption(
    BuildContext context, {
    required String icon,
    required String title,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(vertical: 15),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(color: Colors.grey.shade200),
          ),
        ),
        child: Row(
          children: [
            Container(
              padding: const EdgeInsets.all(8),
              decoration: BoxDecoration(
                color: Colors.grey.shade100,
                borderRadius: BorderRadius.circular(10),
              ),
              child: Image.asset(
                icon,
                width: 24,
                height: 24,
                color: Colors.blue,
              ),
            ),
            const SizedBox(width: 15),
            Text(
              title,
              style: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w500,
              ),
            ),
            const Spacer(),
            const Icon(
              Icons.arrow_forward_ios,
              size: 16,
              color: Colors.grey,
            ),
          ],
        ),
      ),
    );
  }
}
